package com.kabigon.jvm.heap;

import java.util.ArrayList;
import java.util.List;

/**
 * 演示堆内存溢出 java.lang.OutOfMemoryError: Java heap space
 * -Xmx8m
 *
 * @author xu.biao
 * @version v1.0
 * @Package com.kabigon.jvm.heap
 * @data 2023/2/18 1:33
 */
public class Demo1_5 {
    public static void main(String[] args) {
        int i = 0;
        try {
            List<String> list = new ArrayList<>();
            String str = "hello";
            while (true) {
                list.add(str);
                str = str + str;
                i++;
            }
        } catch (Exception e) {
            System.out.println(i);
            e.printStackTrace();
        }
    }
}
